package com.zenithsun.common.review.model;

// default package

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.alibaba.fastjson.annotation.JSONField;

/**
 * 审核信息
 * @author wanglei@enersun.com.cn
 * @createTime 2016-06-17 17:49:52
 */
public class Review implements java.io.Serializable {

	// Fields

	private String id;
	private Short state=-1;
	private Short mark;
	@JSONField(format = "yyyy-MM-dd HH:mm:ss")
	private Date createTime;
	private String busMark;
	private String busId;
	/**
	 * 冗余字段，和reviewdetail中的comments字段保持一致
	 */
	private String comments;
	/**
	 * 最新审核结果，业务使用，不参与存储
	 */
	private Reviewdetail reviewResult;
	
	@JSONField(serialize = false)
	private Set<Reviewdetail> reviewdetails = new HashSet<Reviewdetail>();
	/**
	 * 排序后的内容，不参与存储
	 */
	private List<Reviewdetail> reviewdetailsSort;
	// Constructors

	public List<Reviewdetail> getReviewdetailsSort() {
		return reviewdetailsSort;
	}

	public void setReviewdetailsSort(List<Reviewdetail> reviewdetailsSort) {
		this.reviewdetailsSort = reviewdetailsSort;
	}

	/** default constructor */
	public Review() {
	}

	/** minimal constructor */
	public Review(String id, Short state, Short mark, Date createTime,
			String busMark, String busId,String comments) {
		this.id = id;
		this.state = state;
		this.mark = mark;
		this.createTime = createTime;
		this.busMark = busMark;
		this.busId = busId;
		this.comments=comments;
	}

	/** full constructor */
	public Review(String id, Short state, Short mark, Date createTime,
			String busMark, String busId,String comments,Set<Reviewdetail> reviewdetails) {
		this.id = id;
		this.state = state;
		this.mark = mark;
		this.createTime = createTime;
		this.busMark = busMark;
		this.busId = busId;
		this.comments=comments;
		this.reviewdetails = reviewdetails;
	}

	// Property accessors

	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Short getState() {
		return this.state;
	}

	public void setState(Short state) {
		this.state = state;
	}

	public Short getMark() {
		return this.mark;
	}

	public void setMark(Short mark) {
		this.mark = mark;
	}

	public Date getCreateTime() {
		return this.createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public String getBusMark() {
		return this.busMark;
	}

	public void setBusMark(String busMark) {
		this.busMark = busMark;
	}

	public String getBusId() {
		return this.busId;
	}

	public void setBusId(String busId) {
		this.busId = busId;
	}

	/**
	 * 获取当前的审核信息，不调用getNewReviewDetail()则reviewResult为空
	 */
	public Reviewdetail getReviewResult() {
		return reviewResult;
	}

	public void setReviewResult(Reviewdetail reviewResult) {
		this.reviewResult = reviewResult;
	}

	public Set<Reviewdetail> getReviewdetails() {
		return reviewdetails;
	}

	public void setReviewdetails(Set<Reviewdetail> reviewdetails) {
		this.reviewdetails = reviewdetails;
		//在设置值的时候，找出最新的审核记录，该方法会导致多次查询，效率较低
		//getNewReviewDetail();
	}
	
	public String getComments() {
		return comments;
	}

	public void setComments(String comments) {
		this.comments = comments;
	}
	
	/**
	 * 获取当前的审核信息，不调用则reviewResult为空
	 */
	@Deprecated
	public void getNewReviewDetail(){
		if(this.reviewResult!=null){
			return;
		}
		if(this.getReviewdetails()==null||this.getReviewdetails().size()==0)
		{
			return;
		}
		reviewdetailsSort = new ArrayList<Reviewdetail>(this.getReviewdetails());         
		Collections.sort(reviewdetailsSort);
		this.setReviewResult(reviewdetailsSort.get(0));
	}
	
}